#!/usr/bin/env python
# -*- coding: utf-8
import multiprocessing
import time
import sys
sys.path.append('./modules')
sys.path.append('../mavlink')

from Debug import Debug
import Config
import Console



def main(argv):
	Debug(1, "Starting...")

	# Create multiprocessing data manager
	manager = multiprocessing.Manager()
	state = manager.dict()
	# Populate various usefull data
	state['uptime'] = 0	# System uptime

	# Configuration variables
	state['config'] = Config.Load('icarus.json')

	# A holder for all processes
	Processes = list()

	# Console process
	Processes.append(multiprocessing.Process(target = Console.Run, args = (state,)))


	# Start runner threads
	for p in Processes: p.start()

	# Main waiter loop and uptime counter
	while True:
		state['uptime'] += 1
		time.sleep(1)
		Debug(3, "Main loop ticking, uptime: {0} seconds".format(state['uptime']))
		Debug(4, state)


	# Wait for all processes to complete
	for p in Processes: p.join()

	# All done
	Debug(1, "All completed, terminating")


# Main runner
if __name__ == '__main__': main(sys.argv)

# End-of-file
